import { myGetRequest,myPostRequest } from "../../../utils/myRequest.js"
const app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    try {
      var userInfo = wx.getStorageSync('userInfo')
      if (userInfo) {
        this.setData({
            userInfo: userInfo
          })
      }
    } catch (e) {
      // Do something when catch error
      console.log("页面初始化失败： "+e)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  logout:function(){
    const that=this
    wx.showModal({
      title: '提示',
      content: '是否退出登录',
      success(res) {
        if (res.confirm) {
          that.cleanUserInfo();
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  unbind:function(){
    const that=this
    wx.showModal({
      title: '提示',
      content: '确定解除绑定的齐鲁工惠账户',
     async success(res) {
        if (res.confirm) {
          const res=  await myPostRequest({
            url:'/user/unbind',
            data:that.userInfo
          })
          if( res.statusCode == 200 && res.data.code==0){
            that.cleanUserInfo();
          }else{
            wx.showToast({
              title: res.data.message,
              icon: 'none',
              duration:2500

            })
          }


        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  cleanUserInfo:function(){
    try {
      wx.removeStorageSync('userInfo')
    } catch (e) {
      // Do something when catch error
    }
    wx.redirectTo({
      url: '/pages/login/login'
    })
  }
 
})